Microcomputers today are used to control a wide variety of products ranging from a simple household appliance to a complex automobile. One of the important uses carried out by the microcomputer is timing control. Timing control can also range from the very simple to the very complex. A household appliance may only require a microcomputer timer to count how much time has elapsed between two events in order to control the appliance. An automobile, on the other hand, may require the timer to generate or recognize complex waveforms in order to control the automobile engine.
An important use for timer functions, other than control, is the generation of clocks for communication systems. Communication systems transfer data between multiple locations. Some communication systems require one or more clocks in order to determine when the various bits of data are to be sent. A timer is a convenient device which can be used to generate the clocks required by a communication system. A timer can also be used to generate a wide range of output waveforms that can be used for purposes other than control and the clocking of communication information.
In order to discuss timers, it is necessary to define the basic terminology of a waveform, such as period, cycle, frequency, pulse width, and duty cycle. Period and cycle are being used synonymously in this document. The period or cycle of a waveform is the length of time between any two rising edges or any two falling edges of the waveform. The frequency of a waveform is the inverse of the period, that is frequency=1/period. As the period increases, the frequency decreases. Therefore, a waveform with a long period has a low frequency.
The pulse width of a waveform is the length of time that the pulse remains in a predetermined state, either high or low. The duty cycle of a waveform is the percentage of time that the waveform is high during the total waveform period. For example, a waveform that has a 70% duty cycle is high for 70% of the total period and low for the remaining 30% of the period. A waveform that has a 50% duty cycle is high for 50% of the total period and low for the remaining 50% of the period. And a waveform with a 20% duty cycle is high for 20% of the total period and low for the remaining 80% of the period.
Many timers operate by using an input clock, a counter, and some type of compare logic. The counter is used to keep track of the length of time that has elapsed from an initial starting time. The counter is incremented by the first edge of the input clock. On the second edge of the input clock, the contents of the counter are compared to a preprogrammed value to determine if the two values match. If a match occurs, the timer has determined that a sufficient length of time has elapsed since the initial starting time. The timer then performs the appropriate function, such as causing an interrupt or driving a value on an output pin. If a match does not occur, the timer has determined that a sufficient time has not elapsed since the initial starting time and the counter is again incremented on the next edge of the input clock.
Because the counter value changes after each increment, the compare operation must be performed after each increment of the counter. If a compare is not performed after each increment, a match may occur and yet go undetected. There are only two edges during each period of the input clock. The first edge is used to increment the counter and the second edge is used to trigger the compare operation. As a result, the counter can only be incremented once during each period of the input clock. Thus the effective rate at which the counter can count is limited by the frequency of the input clock. A standard counter with an input clock frequency of "F" can only count at the rate of "F". For example, a counter with an input clock of 6 megahertz can only count at the rate of 6 megahertz.
The rate at which a counter can count determines the resolution of the timer. The resolution of existing timers is limited by the frequency of the input clock. Many microcomputer customers want timers that have greater resolution. And unfortunately, the easy solution of merely increasing the frequency of the input clock in order to increase the resolution of the timer is usually not a viable option. The input clock to the timer is usually the fastest system clock operating throughout the entire microcomputer. Increasing the speed of this system clock affects all parts of the system, not just the timer. Some circuitry within the microcomputer will not operate correctly above a certain maximum frequency, and this maximum frequency may not be great enough to produce the required resolution in the timer.